package com.longge;

public class FindTheLongestBalancedSubstring {

    public int findTheLongestBalancedSubstring(String s) {

        char[] chars = s.toCharArray();
        int[] arr = new int[2];
        int ans = 0;
        for (int i = 0; i < chars.length; i++) {
            if (i == 0 || (chars[i - 1] == '1' && chars[i] == '0')) {
                arr[0] = 0;
                arr[1] = 0;
            }
            if (chars[i] == '0') {
                arr[0] = arr[0] + 1;
            } else {
                arr[1] = arr[1] + 1;
            }

            ans = Math.max(ans, 2 * Math.min(arr[0], arr[1]));

        }
        return ans;
    }

}
